<?php
use yii\web\View;
use yii\helpers\Html;
use app\assets\WechatAsset;
$this->registerJsFile('@web/wechat/js/moment.min.js',['depends'=>[WechatAsset::className()], 'position' =>View::POS_END]);
$this->registerCssFile('@web/wechat/css/daterangepicker.css', ['depends' => [WechatAsset::className()], 'position' =>View::POS_END]);
$this->registerJsFile('@web/wechat/js/daterangepicker.js',['depends'=>[WechatAsset::className()], 'position' =>View::POS_END]);
$url = \Yii::$app->urlManager->createUrl('wechat/get-news-total');
// $url = Url::to(['site/index']);
$js = <<<EOT
$(function() {
    $('input[name="daterange"]').daterangepicker({
        locale: {
            format: 'YYYY/MM/DD'
        }
    });
    $('#daterang').on('apply.daterangepicker', function(ev, picker) {
        var te = $('#daterang').val();
        te = te.split("-");
        var startime = te[0];
        var endtime = te[1];
        var difftime = DateDiff(startime, endtime);
        if (difftime >3)
        {
            alert('时间间隔不能超过3天');
        }
      });

      function DateDiff(sDate1, sDate2) {  //sDate1和sDate2是yyyy-MM-dd格式
            var aDate, oDate1, oDate2, iDays;
            aDate = sDate1.split("-");
            oDate1 = new Date(aDate[1] + '-' + aDate[2] + '-' + aDate[0]);  //转换为yyyy-MM-dd格式
            aDate = sDate2.split("-");
            oDate2 = new Date(aDate[1] + '-' + aDate[2] + '-' + aDate[0]);
            iDays = parseInt(Math.abs(oDate1 - oDate2) / 1000 / 60 / 60 / 24); //把相差的毫秒数转换为天数
            return iDays;  //返回相差天数
        }

});
EOT;

$this->registerJs($js, View::POS_END);
?>
<form action="" method="post" id='register_form'>
    <div class="col-md-4 col-md-offset-2">
                <h4>Date Range</h4>
                <input type="text" id="daterang" class="form-control" name="daterange">
                <i class="glyphicon glyphicon-calendar fa fa-calendar"></i>
    </div>
    <div class="weui_btn_area">
        <!-- <a class="weui_btn weui_btn_primary" href="register" id="showTooltips">立即开卡</a> -->
        <div class="form-group">
        <?= Html::submitButton('查询', ['class' => 'btn btn-success']) ?>
        </div>
        <input name="_csrf" type="hidden" id="_csrf" value="<?= Yii::$app->request->csrfToken ?>">
    </div>
</form>